<template>
	<view>
		<view class="wrap">
			<cu-custom bgColor="bg-gradual-blue" :isBack="true">
				<block slot="content">发布任务</block>
			</cu-custom>
			<view>

				<form @submit="formSubmit">
					<view class="wai">
						我的姓名：
						<view class="shurudiv">
							<input type="text" placeholder="请输入" name="name" class="shuru"/>
						</view>
					</view>
					<view class="wai">
						联系电话：
						<view class="shurudiv">
							<input type="text" placeholder="请输入" name="phone" class="shuru"/>
						</view>
					</view>
					<view class="wai">
						收货地址：
						<view class="shurudiv">
							<input type="text" placeholder="请输入" name="address" class="shuru"/>
						</view>
					</view>
					<view class="wai">
						送货时间：
						<view class="shurudiv">
							<input type="text" placeholder="请输入" name="time" class="shuru"/>
						</view>
					</view>
					<view class="wai">
						取件地址：
						<view class="shurudiv">
							<input type="text" placeholder="请输入" name="locker" class="shuru"/>
						</view>
					</view>
					<view class="wai">
						取件号码：
						<view class="shurudiv">
							<input type="text" placeholder="请输入" name="code" class="shuru"/>
						</view>
					</view>
					<view class="wai">
						任务赏金：
						<view class="shurudiv">
							<input type="text" placeholder="请输入" name="price" class="shuru"/>
						</view>
					</view>
					
					<view class="bg-white">
						<upimg-box @callParent="callImgList" :defaultImgsList="[]"></upimg-box>
						<view class="padding flex flex-direction margin-top-sm">
							<button class="cu-btn bg-gradual-blue shadow lg" form-type="submit">发布</button>
						</view>
					</view>
				</form>
				
			</view>
		</view>	
		 
		<!-- 模拟提示 -->
		<u-toast ref="uToast" />
		<u-popup v-model="show" mode="center" :mask-close-able="false" border-radius="24" width="580">
			<view class="padding-xl">
				<view>当前进度：</view>
				<u-line-progress active-color="#2979ff" height="20" :percent="progress"></u-line-progress>
			</view>
		</u-popup>
	</view>
</template>

<script> 
	import upimgBox from "@/components/upimgbox.vue";
	import mdate from "@/common/date.js"; 
	import { mapGetters } from 'vuex';
	export default {
		components:{
			upimgBox,
		},
		computed: {
			...mapGetters(['userInfo'])
		},
		data:function(){
			return {
				imgsList:[],
				show:false,
				progress:0
			}
		},
		onLoad:function(){
			
		},
		methods:{
			callImgList:function(e){
				this.imgsList = e;			
			},
			//上传表单
			formSubmit:function(e){
				var params=e.detail.value;
				console.log(params)
				if( params.name =='' || params.address==''|| params.phone==''|| params.price==''){
					uni.showToast({
						// title:"标题、内容必填，图片至少上传一张！",
						title:"信息未填完整",
						icon:'none'
					})
					return
				}
				params.createTime=new Date().Format("yyyy-MM-dd hh:mm:ss");			 
				params.imgList=this.imgsList;
				params.view_num=1;
				params.employerId=this.userInfo._id;
				// params.comment_num=0;
				params.status=0;
				params.comment="";
				params.workerId="";
				uniCloud.callFunction({
					name: 'task',
					data: {
						cloudAction:"save",
						params:params
					}
				}).then((res) => {
					console.log(res);
					uni.showToast({
						title:"发布成功"
					}) 
					uni.reLaunch({
						url:"/pages/take/take"
					})
					
				}).catch((err) => {
					console.error(err)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.wrap {
	display: flex;
	flex-direction: column;
	height: calc(100vh - var(--window-top));
	width: 100%;
}
/*.swiper-box {
	flex: 1;
	height: 70vh;
}
.swiper-item {
	height: 100%;
}*/
.wai{
	display:flex;
	align-items:center ;
	margin: 10upx;
}
.shurudiv{
	width: 70%;
	display: flex;
	height: 60upx;
	align-items:center ;
	border:1px solid #c8c7cc;
	border-radius: 10upx;
	background-color: #FFFFFF;
}
.shuru{
	overflow:hidden;
	font-size: 14px;
	line-height: 2;
	padding-left: 20upx;
	
}
</style>
